<template>
	<view>
		<view class="goodlist_item">
			<view @click="goto(item)" class="item" v-for="(item,index) in GoodList" :key="index">
				<my-goods :item="item"></my-goods>
			</view>
		</view>
	</view>
</template>d

<script>
	export default {
		data() {
			return {
				queryObj: {
					query: '',
					cid: '',
					pagenum: 1,
					pagesize: 10
				},
				GoodList: [],
				Total: 0,
				isGET: false
			}
		},
		methods: {
			async GetGoodsList (cb) {
				this.isGET = true
				const { data: res } = await uni.$http.get('/api/public/v1/goods/search',this.queryObj)
				cb && cb()
				this.isGET = false
				if (res.meta.status !== 200) return uni.$showMsg()
				this.GoodList = [...this.GoodList,...res.message.goods]
				this.Total = res.message.total
			},
			goto (item) {
				uni.navigateTo({
					url: '../shop_details/shop_details?goods_id=' + item.goods_id
				})
			}
		},
		onLoad(options) {
			this.queryObj.query = options.query || ''
			this.queryObj.cid = options.cid || ''
			this.GetGoodsList()
		},
		onReachBottom() {
			if (this.queryObj.pagesize * this.queryObj.pagenum >= this.Total) return uni.showToast({
				title: '数据加载完了',
				icon: 'none',
				duration: 1500
			})
			if (this.isGET) return
			
			this.queryObj.pagenum += 1
			this.GetGoodsList()
		},
		onPullDownRefresh() {
			this.Total = 0
			this.queryObj.pagesize = 10
			this.queryObj.pagenum = 1
			this.GoodList = []
			this.GetGoodsList((cb) => {uni.stopPullDownRefresh()})
		}
	}
</script>

<style>

</style>
